package com.sogoodsoft.service.account;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.sogoodsoft.dao.account.AuthorityDao;
import com.sogoodsoft.dao.common.CommonHibernateDao;
import com.sogoodsoft.entity.account.Authority;
import com.sogoodsoft.entity.account.Role;
import com.sogoodsoft.service.common.AbstractService;

@Component
@Transactional
public class AuthorityService extends AbstractService<Authority,Long> {

	private AuthorityDao dao;
	@SuppressWarnings({ "unchecked"})
    @Override
	public CommonHibernateDao getDao() {
		return dao;
	}
	
	@Autowired
	public void setDao(AuthorityDao dao) {
		this.dao = dao;
	}

	/* 
	 *删除时，需更新与role的对应关系
	 */
	@Override
	public void delete(Authority t) {
		List<Role> list = dao.createQuery("select r from Role r left join r.authorityList a where a.id=?",t.getId()).list();
		for(Role r :list){
			r.getAuthorityList().remove(t);
		}
		dao.delete(t);
	}
	
	

}
